package org.apache.solr.util;

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 *
 *
 **/
// Since Arrays.equals doesn't implement offsets for equals
public class ArraysUtils {

	/**
	 * See if two array slices are the same.
	 * 
	 * @param left
	 *            The left array to compare
	 * @param offsetLeft
	 *            The offset into the array. Must be positive
	 * @param right
	 *            The right array to compare
	 * @param offsetRight
	 *            the offset into the right array. Must be positive
	 * @param length
	 *            The length of the section of the array to compare
	 * @return true if the two arrays, starting at their respective offsets, are
	 *         equal
	 * 
	 * @see java.util.Arrays#equals(char[], char[])
	 */
	public static boolean equals(char[] left, int offsetLeft, char[] right,
			int offsetRight, int length) {
		if ((offsetLeft + length <= left.length)
				&& (offsetRight + length <= right.length)) {
			for (int i = 0; i < length; i++) {
				if (left[offsetLeft + i] != right[offsetRight + i]) {
					return false;
				}

			}
			return true;
		}
		return false;
	}
}
